package com.juneyao.bigdata.controller;

import com.juneyao.bigdata.domain.PeopleGroup;
import com.juneyao.bigdata.domain.PeopleGroupId;
import com.juneyao.bigdata.domain.ResultParam;
import com.juneyao.bigdata.service.SetLogicService;
import com.juneyao.bigdata.service.UserInteractiveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author quanbiao
 * @date 2018-06-28
 * 集合controller
 */
@RequestMapping("/set")
@RestController
public class SetController {

    private Logger logger = LoggerFactory.getLogger("SetController");

    @Autowired
    private UserInteractiveService userService;

    @Autowired
    private SetLogicService setlogicService;

    /**
     * 集合逻辑新增或修改
     * @param str
     * @return
     */
    @RequestMapping(value = "addormodify",method = {RequestMethod.GET,RequestMethod.POST})
    public ResultParam addOrModify(@RequestBody String str){
        logger.info("addormodify json="+str);
        str = str.replace("\\", "");
        ResultParam result = this.setlogicService.insertCrowdLogic(str);
        return result;
    }

    /**
     * 集合人数汇总
     * @param peopleGroupId
     * @return
     */
    @RequestMapping(value = "aggregate",method = {RequestMethod.GET, RequestMethod.POST})
    public PeopleGroup setAggregate(@RequestBody PeopleGroupId peopleGroupId){
        logger.info("logger starting....");
        logger.info("集合人数汇总 PeopleGroupId="+peopleGroupId);
        //执行查询
        PeopleGroup peopleGroup = userService.peopleGroupSum(peopleGroupId);

        logger.info("PeopleGroup:"+peopleGroup.toString());
        return peopleGroup;
    }

}
